<!DOCTYPE html>
<html>
	<head>
		<title>SRS</title>
		<meta charset="utf-8">
		<style>
body{
	padding-top: 30px;
}
		</style>
		<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
		<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
		<script type="text/javascript" src="js/adapter-7.4.0.min.js"></script>
		<script type="text/javascript" src="js/srs.sdk.js"></script>
		<script type="text/javascript" src="js/winlin.utility.js"></script>
		<script type="text/javascript" src="js/srs.page.js"></script>
	</head>
	<body>
		<div class="container">
			<div class="form-inline">
				URL:
				<input type="text" id="txt_url" class="input-xxlarge" value="">
				<button class="btn btn-primary" id="btn_play">播放视频</button>
			</div>

			<label></label>
			<video id="rtc_media_player" width="100%" controls autoplay></video>
		</div>
		<script type="text/javascript">
			$(function(){
				var sdk = null; // Global handler to do cleanup when replaying.
				var startPlay = function() {
					$('#rtc_media_player').show();

					// Close PC when user replay.
					if (sdk) {
						sdk.close();
					}
					sdk = new SrsRtcPlayerAsync();

					// https://webrtc.org/getting-started/remote-streams
					$('#rtc_media_player').prop('srcObject', sdk.stream);
					// Optional callback, SDK will add track to stream.
					// sdk.ontrack = function (event) { console.log('Got track', event); sdk.stream.addTrack(event.track); };

					// For example: webrtc://r.ossrs.net/live/livestream
					var url = $("#txt_url").val();
					sdk.play(url).then(function(session){
					}).catch(function (reason) {
						sdk.close();
						$('#rtc_media_player').hide();
						console.error(reason);
					});
				};

				$('#rtc_media_player').hide();
				var query = parse_query_string();
				srs_init_rtc("#txt_url", query);

				$("#btn_play").click(function() {
					$('#rtc_media_player').prop('muted', false);
					startPlay();
				});

				if (query.autostart === 'true') {
					$('#rtc_media_player').prop('muted', true);
					console.warn('For autostart, we should mute it, see https://www.jianshu.com/p/c3c6944eed5a ' +
						'or https://developers.google.com/web/updates/2017/09/autoplay-policy-changes#audiovideo_elements');

					startPlay();
				}
			});
		</script>
	</body>
</html>
